package com.qfedu.mapper;

import com.qfedu.model.Item;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
public interface ItemMapper {
    @Select("select count(*) from item where status=1")
    long count();
    @Select("select * from item where status=1 limit #{currentPage},#{pageSize}")
    List<Item> findPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    @Insert("insert into item(iid,iname,starttime,endtime,suid,updatetime)" +
            " values(#{iid},#{iname},#{starttime},#{endtime},#{suid},#{updatetime}) ")
    int addItem(Item item);

    @Select("select * from item where iid=#{iid} and status=1 ")
    Item findById(String iid);
    @Select("select * from item where suid=#{suid} and status=1 ")
    List<Item> findBySuid(String suid);

    @Update("update item set iname=#{iname},starttime=#{starttime},endtime=#{endtime}," +
            "suid=#{suid},updatetime=#{updatetime} where iid=#{iid}")
    int editItem(Item item);

    //删除
    @Update("update item set status=0 where iid = #{iid}")
    int deleteByIid(String iid);
}
